#include <windows.h>

#include "lib.h"
#include "libglob.h"

static int32	cProcessesAttached = 0;
static HANDLE	chInst = (HANDLE)0;

#ifdef _MSC_VER
extern "C" {
	BOOL WINAPI _CRT_INIT(HINSTANCE, DWORD, LPVOID);
}
#	define initCRT(a,b,c)	if (!_CRT_INIT((HINSTANCE)a,b,c)) return FALSE
#else
#	define initCRT(a,b,c)	NOTUSED3(a,b,c);
#endif

static HMODULE __stdcall LoadUnicowsProc(void){
	return LoadLibraryA("unicows.dll");
}
extern "C" HMODULE (_stdcall *_PfnLoadUnicows)(void) = &LoadUnicowsProc;


int APIENTRY
LibMain(HANDLE hInst, DWORD fdwReason, LPVOID lpReserved)
{
	initCRT(hInst, fdwReason, lpReserved);

	switch (fdwReason)
	{
		case DLL_PROCESS_ATTACH:
			chInst = hInst;

			if (cProcessesAttached++)
			{
				return TRUE;
			}

			return TRUE;

		case DLL_PROCESS_DETACH:
			if (0 == --cProcessesAttached)
			{
			}
			break;

		default:
			break;
	}

	return TRUE;
}
